package com.zgc.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.transaction.annotation.Transactional;

import com.zgc.dao.IsourceInfoDao;
import com.zgc.domain.PageBean;
import com.zgc.domain.TeachSource;
import com.zgc.service.IsourceInfoService;

@Transactional
public class IsourceInfoServiceImpl implements IsourceInfoService{
	@Resource
	private IsourceInfoDao isourceInfoDao;
	
	public void saveSourseInfo(TeachSource teachSource){
	isourceInfoDao.saveSourseInfo(teachSource);
	    }

	@Override
	public List<TeachSource> qryAllSource() {
		List<TeachSource> list = isourceInfoDao.qryAllSource();
		return list;
	}

	@Override
	public List<TeachSource> qryBySpec(String speciality) {
		return isourceInfoDao.qryBySpec(speciality);
	}

	@Override
	public List<TeachSource> qryByKey(String keyWord) {
		return isourceInfoDao.qryByKey(keyWord);
	}

	@Override
	public void updateSourById(TeachSource teachSource) {
		isourceInfoDao.updateSourById(teachSource);
	}

	@Override
	public TeachSource qrySourceById(int sourceId) {
		return isourceInfoDao.qrySourceById(sourceId);
	}

	@Override
	public void delSourById(int sourceId) {
		isourceInfoDao.delSourById(sourceId);
	}

	@Override
	/**   
	 * 分页查询     
	 * @param pageSize  每页显示多少记录   
	 * @param currentPage 当前页   
	 * @return 封装了分页信息的bean   
	 */    
	public PageBean queryForPage(int pageSize, int page,String hql) {    
	int allRow = isourceInfoDao.getAllRowCount(hql);  //总记录数    
	int totalPage = PageBean.countTatalPage(pageSize, allRow); //总页数    
	final int offset = PageBean.countOffset(pageSize, page); //当前页开始记录    
	final int length = pageSize; // 每页记录数    
	final int currentPage = PageBean.countCurrentPage(page); // 当前页    
	List list = isourceInfoDao.queryForPage(hql, offset, length); //    
	//把分页信息保存到Bean当中    
	PageBean pageBean  = new PageBean();    
	pageBean.setPageSize(pageSize);    
	pageBean.setCurrentPage(currentPage);    
	pageBean.setAllRow(allRow);    
	pageBean.setTotalPage(totalPage);    
	pageBean.setList(list);    
	pageBean.init();    
	return pageBean;    
	}    

}
